package com.g5.edu.service.impl;

import com.g5.edu.common.Result;
import com.g5.edu.dto.ForumInfoDTO;
import com.g5.edu.model.DfForumInfo;
import com.g5.edu.mapper.DfForumInfoMapper;
import com.g5.edu.service.IDfForumInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 论坛话题信息 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-10-29
 */
@Service
public class DfForumInfoServiceImpl extends ServiceImpl<DfForumInfoMapper, DfForumInfo> implements IDfForumInfoService {

    @Autowired(required = false)
    private DfForumInfoMapper dfForumInfoMapper;

    /**
     * 获取前6条话题
     * @param num
     */
    @Override
    public List<ForumInfoDTO> getTopicList(Integer num) {
        //从数据库查出来的数组
        List<DfForumInfo> list = dfForumInfoMapper.getTopicList(num);
        //要返回给页面的模型数据数组
        List<ForumInfoDTO> arr = new ArrayList<>();
        if (list != null && list.size()>0){
            for (DfForumInfo pojo : list){
                //页面数据模型
                ForumInfoDTO dto = new ForumInfoDTO();
                //设置id
                dto.setId(pojo.getId());
                //设置标题
                dto.setTopicTitle(pojo.getTopicTitle());
                //设置内容
                dto.setTopicContent(pojo.getTopicContent() );
                //设置图片路径
                dto.setImagePath(pojo.getImagePath() );
                arr.add(dto);
            }
        }
        //返回这个数组
        return arr;
    }
}
